﻿--|--------------------------------------------------------------------------------
--| [UpdateCar] - Insert Procedure Script for Game
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[UpdateCar]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[UpdateCar]
GO

CREATE PROCEDURE [dbo].[UpdateCar]
(
	@ID int output, 
	@Name nvarchar(50), 
	@Description nvarchar(50), 
	@MaxSendingPause int,
	@Model nvarchar(250),
	@RegistrationNumber nvarchar(50),
	@Color nvarchar(50))
AS
	SET NOCOUNT ON

UPDATE dbo.Entity SET 
	Name = @Name, 
	Description = @Description, 
	MaxSendingPause = MaxSendingPause
	WHERE ID = @ID

DELETE FROM dbo.EntityAttribute
WHERE EntityID = @ID 
	AND EntityAttributeTypeID IN ('MODL','SRN','CLR')

INSERT INTO dbo.EntityAttribute (EntityID, EntityAttributeTypeID, Value)
		  SELECT @ID, 'MODL', @Model
UNION ALL SELECT @ID, 'SRN', @RegistrationNumber
UNION ALL SELECT @ID, 'CLR', @Color
GO
 